package com.bnz.controller;


import com.bnz.entity.Classes;
import com.bnz.entity.Student;
import com.bnz.service.IClassesService;
import com.bnz.service.IStudentService;
import com.bnz.vo.Message;
import com.bnz.vo.PageVo;
import com.bnz.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xy
 * @date 2022/10/21
 */

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private IStudentService studentService;
   @Autowired
    private IClassesService classesService;

    @RequestMapping("/list")
    public Message list(@RequestBody StudentVo vo) {

        PageVo<Student> search = studentService.search(vo);
        return Message.ok().data("data", search);
    }

    @RequestMapping("/add")
    public Message add(@RequestBody Student student) {
         studentService.add(student);
        return Message.ok().data("data", "添加学生成功！");
    }

    @RequestMapping("/delete/{id}")
    public Message delete(@PathVariable("id") Integer id) {
        studentService.deleteById(id);
        return Message.ok().data("data", "删除学生成功！");
    }
    @RequestMapping("/class")
    public Message getClassList() {
        List<Classes> classes = classesService.queryAll();
        return Message.ok().data("data", classes);
    }
    @RequestMapping("/batchdel/{sids}")
    public Message batchDel(@PathVariable("sids") Integer[] sids) {
          studentService.delete(sids);
        return Message.ok().data("data", "删除成功");
    }
    @RequestMapping("/modify")
    public Message modify(@RequestBody Student student) {
        int update = studentService.update(student);

        return Message.ok().data("data", "修改学生失败！");
    }
}
